package com.hehao.java_basic.thread;

import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @Author hehao
 * @Date 2022/3/9 21:57
 * @Version
 */

public class TestJUC {
    public static void main(String[] args) {
        CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<>();
        for (int i = 0; i < 10000; i++) {
            new Thread(()->{
                synchronized (list) {

                    list.add(Thread.currentThread().getName());
                }
            }).start();
        }
//        try {
//            Thread.sleep(3000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        System.out.println(list.size());
    }
}
